# Mulan Permissive Software License，Version 2

# Mulan Permissive Software License，Version 2 (Mulan PSL v2)

# January 2020 http://license.coscl.org.cn/MulanPSL2

# Copyright (c) 2024 BerryFox
# L.M.F. is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan
# PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#          http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
# KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
#
import pygame
from pygame.locals import *

from mods.settings import Settings

settings = Settings()

def print_text(x, y, text, size, target, color=(0,0,0), shadow=True, _font=None):
    """Use Pygame to print text"""
    font = pygame.font.SysFont(_font, size)
    if shadow:
        #Has shadow?
        imgText = font.render(text, True, settings.color_shadow)
        target.blit(imgText, (x-2,y-2))
    imgText = font.render(text, True, color)
    target.blit(imgText, (x,y))
    pygame.display.update()

def print_picture(x, y, file_name, target, scale_value=1):
    """Draw pictures"""
    picture = pygame.image.load(f"data/{file_name}").convert_alpha()
    width, height = picture.get_size()
    picture = pygame.transform.smoothscale(picture, \
        (width//scale_value, height//scale_value))
    target.blit(picture, (x, y))

class PrintSpecial:
    """Print something special"""
    def print_game_name(self, target):
        """Start page"""
        print_text(_font=None, x=300, y=200, size=50, \
            text="Light Mirror Flag(L.M.F.) pre1-1",color=settings.color_blue, \
            target=target)
        print_text(_font="mvboli", x=400, y=300, size=30, text="By Whale Fall Studio", \
            color=settings.color_green, target=target)
        print_picture(x=300, y=400, file_name="鲸落工作室(图标).jpeg", \
            target=target, scale_value=10)

    def print_error_text(self, target, error_text):
        """Error information"""
        print_text(_font=None, x=30, y=30, size=20, text=error_text, \
            color=settings.color_red, target=target, shadow=False)

    def print_thanks(self, target):
        """At last"""
        print_text(_font="candara", x=300, y=200, size=50, \
            text="Thanks for your playing!", color=settings.color_green, \
            target=target, shadow=False)

    def print_about_studio(self, target):
        """About us"""
        print_text(x=100, y=100, size=30, text="Whale Fall Studio", \
            color=settings.color_light_blue, target=target)
        with open("data/About_our_studio.txt", "r", encoding="utf-8") as file:
            print_y = 125
            offset_y = 20
            print_x = 100
            offset_x = 15
            file_read = file.read()
            for line in file_read:
                if line == '\n':
                    print_text(x=200, y=print_y, size=20, text=line, \
                    color=settings.bg_color, shadow=False, target=target)
                    print_y += offset_y
                    print_x = 100
                else:
                    print_text(_font="franklingothicmedium", \
                        x=print_x, y=print_y, size=20, text=line, \
                        color=settings.color_light_blue, shadow=False, target=target)
                    print_x += offset_x

        print_picture(x=10, y=230, file_name="鲸落工作室(宣传).jpeg", \
            target=target, scale_value=4)

    def print_about_members(self, target):
        """Print something about members"""
        print_text(_font="franklingothicmedium", x=400, y=100, size=30, \
            text="Our members", color=settings.color_purple, target=target)

        print_text(_font="microsoftjhengheimicrosoftjhengheiuibold", \
            x=150, y=130, size=30, text="BerryFox", \
            color=settings.color_deep_blue, target=target, shadow=False)
        print_picture(x=90, y=110, file_name="member_BerryFox_head_portrait.jpeg", \
            target=target, scale_value=4)
        with open("data/About_members_BerryFox.txt", "r", encoding="utf-8") as file:
            print_y = 170
            offset_y = 20
            print_x = 100
            offset_x = 15
            file_read = file.read()
            for line in file_read:
                if line == '\n':
                    print_text(x=200, y=print_y, size=20, text=line, \
                    color=settings.bg_color, shadow=False, target=target)
                    print_y += offset_y
                    print_x = 100
                else:
                    print_text(_font = "inkfree", \
                        x=print_x, y=print_y, size=20, text=line, \
                        color=settings.color_light_blue, shadow=False, \
                        target=target)
                    print_x += offset_x

    def print_about_LMF(self, target):
        print_text(_font="franklingothicmedium", x=400, y=100, size=30, \
            text="How we start?", color=settings.color_purple, target=target)

        with open("data/About_LMF.txt", "r", encoding="utf-8") as file:
            print_y = 170
            offset_y = 20
            print_x = 100
            offset_x = 15
            file_read = file.read()
            for line in file_read:
                if line == '\n':
                    print_text(x=200, y=print_y, size=20, text=line, \
                    color=settings.bg_color, shadow=False, target=target)
                    print_y += offset_y
                    print_x = 100
                else:
                    print_text(_font = "couriernew", \
                        x=print_x, y=print_y, size=20, text=line, \
                        color=settings.color_light_blue, shadow=False, \
                        target=target)
                    print_x += offset_x